"""
@Project ：Python_Learning 
@File    ：27.移除元素.py
@IDE     ：PyCharm 
@Author  ：zhupp
@Date    ：2024/10/16 10:56 
"""
class Solution:
    def removeElement(self, nums: list[int], val: int) -> int:
        index = 0
        if len(nums) == 1 and nums[0] == val:
            nums.pop()
            return len(nums)

        for i in range(len(nums)):
            if nums[i] != val:
                nums[index] = nums[i]
                index += 1

        return len(nums[:index])


s = Solution()
print(s.removeElement([2], 3))